﻿using System;
using System.Collections.Generic;
using EmitMapper;
using EmitMapper.MappingConfiguration;

namespace Tin.Esay.Framework.Common.Utility
{
    public static class Translator
    {
        public static TTo Map<TFrom, TTo>(TFrom from)
        {
            return EmitMapper.ObjectMapperManager.DefaultInstance.GetMapper<TFrom, TTo>().Map(from);
        }

        public static List<TTo> Mapper<TFrom, TTo>(this List<TFrom> from)
        {
            return EmitMapper.ObjectMapperManager.DefaultInstance.GetMapper<List<TFrom>, List<TTo>>().Map(from);
        }

        public static TTo MapperDateHandle<TFrom, TTo>(this TFrom from) where TFrom : class
        {
            var mapper = ObjectMapperManager.DefaultInstance.GetMapper<TFrom, TTo>(
                new DefaultMapConfig()
                 .ConvertUsing<DateTime, string>(value => value.ToString("yyyy年MM月dd日")));
            return mapper.Map(from);
        }

        public static List<TTo> MapperDateHandle<TFrom, TTo>(this List<TFrom> from)
        {
            var mapper = ObjectMapperManager.DefaultInstance.GetMapper<List<TFrom>, List<TTo>>(
                 new DefaultMapConfig()
                  .ConvertUsing<DateTime, string>(value => value.ToString("yyyy年MM月dd日")));
            return mapper.Map(from);
        }
    }
}
